import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default () => new Vuex.Store({
  state: {
    title: '',
    readOnly: true,
    test: '',
    middleTitle: '',
    pageTitle: '',
    accessControlInfo: {},
  },
  mutations: {
    setTitle(state, title) {
      state.title = title
    },
    setReadOnly(state, readOnly) {
      state.readOnly = readOnly
    },
    setTest(state, test) {
      state.test = test
    },
    setMiddleTitle(state, test) {
      state.middleTitle = test
    },
    setPageTitle(state, test) {
      state.pageTitle = test
    },
    setAccessControlInfo(state, accessControlInfo) {
      state.accessControlInfo = accessControlInfo
    },
  },
  getters: {
    title(state) {
      return state.title
    },
    readOnly(state) {
      return state.readOnly
    },
    test(state) {
      return state.test
    },
    pageTitle(state) {
      return state.pageTitle
    },
    middleTitle(state) {
      return state.middleTitle
    },
    accessControlInfo(state) {
      return state.accessControlInfo
    },
  },
  actions: {
    async nuxtServerInit({ commit }) {
      // console.log('===nuxtServerInit===')
      // await fetch('https://jsonplaceholder.typicode.com/posts/1')
      //   .then(response => response.json())
      //   .then(data => {
      //     commit('setTest', data)

      //     console.log('nuxtServerInit test::', data)
      //   })
      //   .catch(err => console.log("nuxtServerInit error::", err))
    }
  },
  modules: {}
})

